package com.edu.udistrital.indexing.analyzer;

import java.io.Reader;

import org.apache.lucene.analysis.LowerCaseFilter;
import org.apache.lucene.analysis.StopFilter;
import org.apache.lucene.analysis.TokenStream;
import org.apache.lucene.analysis.Tokenizer;
import org.apache.lucene.analysis.en.EnglishPossessiveFilter;
import org.apache.lucene.analysis.standard.StandardFilter;
import org.apache.lucene.analysis.standard.StandardTokenizer;
import org.apache.lucene.util.Version;

import com.edu.udistrital.util.Configuration;

public class AnalyzerLearningEnglish extends Analyzer{
	
	/**
	 * 
	 */
	public AnalyzerLearningEnglish(Version version) {
		super(version, Configuration.getInstance().getProperty("stopWordsEnglish"));
	}

	@Override
	@SuppressWarnings("deprecation")
	protected TokenStreamComponents createComponents(String arg0, Reader reader) {
	    final Tokenizer source = new StandardTokenizer(MATCH_VERSION, reader);
	    TokenStream result = new StandardFilter(MATCH_VERSION, source);
	    result = new LowerCaseFilter(MATCH_VERSION, result);
	    result = new StopFilter(MATCH_VERSION, result, STOPWORDS);
	    
	    if (MATCH_VERSION.onOrAfter(Version.LUCENE_31))
	      result = new EnglishPossessiveFilter(MATCH_VERSION, result);

//	    if(!stopwords.isEmpty())
//	      result = new KeywordMarkerFilter(result, stopwords);
	    
	    return new TokenStreamComponents(source, result);
	}

}
